//
//  ModulesCollectionViewCell.m
//  littleLight's Project-A
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 light. All rights reserved.
//

#import "ModulesCollectionViewCell.h"
#import <UIImageView+WebCache.h>
@implementation ModulesCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    self.coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, self.contentView.frame.size.width, self.frame.size.height / 7 * 4)];
    [self.contentView addSubview:self.coverImage];
    self.textLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.contentView.frame.size.height / 7 * 4 + 5, self.contentView.frame.size.width - 10, self.contentView.frame.size.height / 7 + 10)];
    self.textLabel.font = [UIFont systemFontOfSize:15];
    self.textLabel.numberOfLines = 0;
    [self.contentView addSubview:self.textLabel];
    
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.contentView.frame.size.height / 7 * 5 + 20, self.contentView.frame.size.width / 2, 30)];
    
    self.priceLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.priceLabel];
    self.priceLabel.font = [UIFont systemFontOfSize:15];
    self.dis_countLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 7 * 5 + 15, self.contentView.frame.size.width, 40)];
    self.dis_countLabel.font = [UIFont systemFontOfSize:20];
    self.dis_countLabel.textColor = [UIColor colorWithRed:1.0 green:94 / 255.0 blue:35 / 255.0 alpha:1];
    [self.contentView addSubview:self.dis_countLabel];
    
    
}

- (void)setModel:(ModulesModel *)model
{
    _model = model;
    
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:_model.title_page]];
    self.textLabel.text = _model.title;
    if (_model.discount_price.length == 0) {
        self.dis_countLabel.text = [NSString stringWithFormat:@"￥%@",_model.price];
        self.priceLabel.text = nil;
        return;
    }
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",_model.price];
    self.dis_countLabel.text = [NSString stringWithFormat:@"￥%@",_model.discount_price];
    
}



@end
